package net.j4love.zookeeper.quickstart;

import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * zookeeper 客户端初始化
 *
 * @author He Peng
 * @create 2017-05-15 13:35
 * @update 2017-05-15 13:35
 * @see
 */
public class ZkClientInitialization {

    private static final Logger LOG = LoggerFactory.getLogger(ZkClientInitialization.class);

    public static void main(String[] args) throws IOException, InterruptedException {

        /*
            param 1 : zk 地址
            param 2 : 连接 zk 服务器的超时时间
            param 3 : watch 实例
         */
        ZooKeeper zk = new ZooKeeper("127.0.0.1:2181",1000,null);
        ZooKeeper.States state = zk.getState();     // CONNECTING

        LOG.debug("ZK 初始化完成, ZK 状态 {}" , state);

        zk.close();

        state = zk.getState();

        LOG.debug("ZK 客户端关闭, ZK 状态 {}" , state);    // CLOSED

    }
}
